<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Article;

/**
 * ArticleSearch represents the model behind the search form about `common\models\Article`.
 */
class ArticleSearch extends Article
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['xa_t_id', 'xa_title', 'xa_abstract', 'xa_title_picture', 'xa_content', 'xa_author', 'xa_type', 'xa_keywords', 'xa_description', 'xa_souch', 'xa_auditing', 'xa_state', 'xa_status', 'xa_operation', 'xa_headlines', 'xa_top', 'xa_recommend', 'xa_c_id', 'xa_browse', 'xa_thumbs', 'xa_enclosure_id', 'xa_create_time', 'xa_update_time', 'xa_remark'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Article::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
        ]);

        $query->andFilterWhere(['like', 'xa_t_id', $this->xa_t_id])
            ->andFilterWhere(['like', 'xa_title', $this->xa_title])
            ->andFilterWhere(['like', 'xa_abstract', $this->xa_abstract])
            ->andFilterWhere(['like', 'xa_title_picture', $this->xa_title_picture])
            ->andFilterWhere(['like', 'xa_content', $this->xa_content])
            ->andFilterWhere(['like', 'xa_author', $this->xa_author])
            ->andFilterWhere(['like', 'xa_type', $this->xa_type])
            ->andFilterWhere(['like', 'xa_keywords', $this->xa_keywords])
            ->andFilterWhere(['like', 'xa_description', $this->xa_description])
            ->andFilterWhere(['like', 'xa_souch', $this->xa_souch])
            ->andFilterWhere(['like', 'xa_auditing', $this->xa_auditing])
            ->andFilterWhere(['like', 'xa_state', $this->xa_state])
            ->andFilterWhere(['like', 'xa_status', $this->xa_status])
            ->andFilterWhere(['like', 'xa_operation', $this->xa_operation])
            ->andFilterWhere(['like', 'xa_headlines', $this->xa_headlines])
            ->andFilterWhere(['like', 'xa_top', $this->xa_top])
            ->andFilterWhere(['like', 'xa_recommend', $this->xa_recommend])
            ->andFilterWhere(['like', 'xa_c_id', $this->xa_c_id])
            ->andFilterWhere(['like', 'xa_browse', $this->xa_browse])
            ->andFilterWhere(['like', 'xa_thumbs', $this->xa_thumbs])
            ->andFilterWhere(['like', 'xa_enclosure_id', $this->xa_enclosure_id])
            ->andFilterWhere(['like', 'xa_create_time', $this->xa_create_time])
            ->andFilterWhere(['like', 'xa_update_time', $this->xa_update_time])
            ->andFilterWhere(['like', 'xa_remark', $this->xa_remark]);

        return $dataProvider;
    }
}
